﻿using Repository.Abstract;
using Repository.NHibernate;
using Services.Abstract;
using Services.Concrete;
using StructureMap;

namespace IoC
{
    public class StructureMap
    {
        public static void Configure()
        {
            ObjectFactory.Initialize(r =>
                                         {
                                             r.Scan(a =>
                                                        {
                                                            a.AssemblyContainingType(typeof(IRepository<>));
                                                            a.AssemblyContainingType(typeof(Repository<>));
                                                            a.WithDefaultConventions();
                                                        });
                                             r.Scan(a =>
                                                       {
                                                           a.AssemblyContainingType(typeof(IService<>));
                                                           a.AssemblyContainingType(typeof(Service<>));
                                                           a.WithDefaultConventions();
                                                       });
                                             r.SetAllProperties(p =>
                                                                    {
                                                                        p.WithAnyTypeFromNamespace("Repository.Abstract");
                                                                        p.WithAnyTypeFromNamespace("Services.Abstract");
                                                                    });
                                         });
        }

        public static T Resolve<T>()
        {
            return ObjectFactory.GetInstance<T>();
        }

        public static void BuildUp(object target)
        {
            ObjectFactory.BuildUp(target);
        }
    }
}